package com.sunday.aomicaichang.ui.login;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.sunday.common.base.BaseActivity;
import com.sunday.common.utils.ToastUtils;
import com.sunday.aomicaichang.R;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by yun_sheng on 2017/5/31.
 */

public class SetPasswordActivity extends BaseActivity {
    @Bind(R.id.edt_password)
    EditText edtPassword;
    @Bind(R.id.edt_confirm_password)
    EditText edtConfirmPassword;
    @Bind(R.id.btn_next)
    TextView btnNext;

    private int type;
    private String token;
    private String logo;
    private String nickName;
    private String password,confirmPassword,code,phone;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register2);
        ButterKnife.bind(this);
        code=getIntent().getStringExtra("code");
        phone=getIntent().getStringExtra("phone");
        type=getIntent().getIntExtra("type",0);
        token=getIntent().getStringExtra("token");
        logo=getIntent().getStringExtra("logo");
        nickName=getIntent().getStringExtra("nickName");
        password=edtPassword.getText().toString();
        confirmPassword=edtConfirmPassword.getText().toString();
        btnNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(!TextUtils.isEmpty(password)){
                    ToastUtils.showToast(mContext,"登录密码不能为空！");
                    return;
                }
                if(!TextUtils.isEmpty(confirmPassword)){
                    ToastUtils.showToast(mContext,"请输入确认登录密码！");
                    return;
                }
                if(!password.equals(confirmPassword)){
                    ToastUtils.showToast(mContext,"登录密码与确认登录密码不符！");
                    return;
                }

                // 要验证的字符串
//                String str = edtPassword.getText().toString();
//                // 正则表达式规则
//                String regEx = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$";
//                Pattern pattern = Pattern.compile(regEx);
//                // 忽略大小写的写法
//                // Pattern pat = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE);
//                Matcher matcher = pattern.matcher(str);
//                // 查找字符串中是否有匹配正则表达式的字符/字符串
//                final boolean rs = matcher.find();
//                if(rs){
                    Intent intent=new Intent(mContext,LoginAreaActivity.class);
                    intent.putExtra("code",code);
                    intent.putExtra("password",edtPassword.getText().toString());
                    intent.putExtra("phone",phone);
                    intent.putExtra("type",type);
                    intent.putExtra("token",token);
                    intent.putExtra("logo",logo);
                    intent.putExtra("nickName",nickName);
                    startActivity(intent);
//                }else {
//                    ToastUtils.showToast(mContext,"密码输入不符合规范！");
//                    return;
//                }
            }
        });
    }

}
